/*
*  Copyright (c) 2001 Sun Microsystems, Inc.  All rights
*  reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*  1. Redistributions of source code must retain the above copyright
*  notice, this list of conditions and the following disclaimer.
*
*  2. Redistributions in binary form must reproduce the above copyright
*  notice, this list of conditions and the following disclaimer in
*  the documentation and/or other materials provided with the
*  distribution.
*
*  3. The end-user documentation included with the redistribution,
*  if any, must include the following acknowledgment:
*  "This product includes software developed by the
*  Sun Microsystems, Inc. for Project JXTA."
*  Alternately, this acknowledgment may appear in the software itself,
*  if and wherever such third-party acknowledgments normally appear.
*
*  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"
*  must not be used to endorse or promote products derived from this
*  software without prior written permission. For written
*  permission, please contact Project JXTA at http://www.jxta.org.
*
*  5. Products derived from this software may not be called "JXTA",
*  nor may "JXTA" appear in their name, without prior written
*  permission of Sun.
*
*  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
*  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
*  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
*  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
*  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
*  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
*  SUCH DAMAGE.
*  ====================================================================
*
*  This software consists of voluntary contributions made by many
*  individuals on behalf of Project JXTA.  For more
*  information on Project JXTA, please see
*  <http://www.jxta.org/>.
*
*  This license is based on the BSD license adopted by the Apache Foundation.
*
*  $Id: Config.java,v 1.1 2004/12/19 23:55:30 gonzo Exp $
*/

package net.jxta.myjxta.misc.unused;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 *
 * @version $Id: Config.java,v 1.1 2004/12/19 23:55:30 gonzo Exp $
 * 
 * @author james todd [gonzo at jxta dot org]
 */

public class Config {

    public static final String CONFIGURATION = "/configuration";
    public static final String TRACE = CONFIGURATION + "/trace";
    public static final String TRACE_LEVEL = TRACE + "/@level";
    public static final String NETWORK = CONFIGURATION + "/network";
    public static final String RENDEZVOUS = NETWORK + "/rendezvous";
    public static final String RENDEZVOUS_IS_RENDEZVOUS = RENDEZVOUS +
            "/@isRendezvous";
    public static final String RENDEZVOUS_URL = RENDEZVOUS + "/url";
    public static final String HTTP = NETWORK + "/http";
    public static final String HTTP_IS_ENABLED = HTTP + "/@isEnabled";
    public static final String HTTP_IPADDRESS = HTTP + "/ipAddress";
    public static final String HTTP_IPADDRESS_SOURCE = HTTP_IPADDRESS +
            "/@source";
    public static final String HTTP_PORT = HTTP + "/port";
    public static final String HTTP_SERVER = HTTP + "/server";
    public static final String HTTP_IS_SERVER = HTTP_SERVER + "/@isServer";
    public static final String HTTP_PROXY = HTTP + "/proxy";
    public static final String HTTP_IS_PROXY = HTTP_PROXY + "/@isProxy";
    public static final String HTTP_PROXY_URL = HTTP_PROXY + "/url";
    public static final String HTTP_RELAY = HTTP + "/relay";
    public static final String HTTP_IS_RELAY = HTTP_RELAY + "/@isRelay";
    public static final String HTTP_RELAY_URL = HTTP_RELAY + "/url";
    public static final String TCP = NETWORK + "/tcp";
    public static final String TCP_MODE = TCP + "/@mode";
    public static final String TCP_IS_ENABLED = TCP + "/@isEnabled";
    public static final String TCP_IPADDRESS = TCP + "/ipAddress";
    public static final String TCP_IPADDRESS_SOURCE = TCP_IPADDRESS +
            "/@source";
    public static final String TCP_PORT = TCP + "/port";
    public static final String TCP_MULTICAST = TCP + "/multicast";
    public static final String TCP_MULTICAST_IS_ENABLED =
      TCP_MULTICAST + "/@isEnabled";
    public static final String TCP_MULTICAST_ADDRESS = TCP_MULTICAST +
            "/@address";
    public static final String TCP_MULTICAST_PORT = TCP_MULTICAST + "/@port";
    public static final String TCP_MULTICAST_SIZE = TCP_MULTICAST + "/@size";
    public static final String TCP_RELAY = TCP + "/relay";
    public static final String TCP_IS_RELAY = TCP_RELAY + "/@isRelay";
    public static final String TCP_RELAY_URL = TCP_RELAY + "/url";
    public static final String APPLICATION = CONFIGURATION + "/application";
    public static final String APPLICATION_PEER = CONFIGURATION + "/peer";
    public static final String APPLICATION_PEER_NAME = APPLICATION_PEER +
            "/@name";
    public static final String APPLICATION_PEER_PRINCIPAL =
        APPLICATION_PEER + "/@principal";
    public static final String APPLICATION_PEER_CREDENTIAL =
        APPLICATION_PEER + "/@credential";

    public static final String ERROR = "error";
    public static final String DEBUG = "debug";
    public static final String INFO = "info";
    public static final String ANY_ALL = "anyAll";
    public static final String DISCOVER = "discover";
    public static final String AUTO = "auto";

    public class Default {
        public static final String TRACE_LEVEL = ERROR;
        public static final String HTTP_IPADDRESS_SOURCE = ANY_ALL;
        public static final int HTTP_PORT = 9700;
        public static final boolean TCP_IS_ENABLED = true;
        public static final String TCP_MODE = AUTO;
        public static final String TCP_IPADDRESS_SOURCE = ANY_ALL;
        public static final int TCP_PORT = 9701;
        public static final String TCP_MULTICAST_ADDRESS = "224.0.1.85";
        public static final int TCP_MULTICAST_PORT = 1234;
        public static final int TCP_MULTICAST_SIZE = 16384;
    }

    private static final String IPADDRESS = "0.0.0.0";

    public static String getIPAddress() {
        String ip = IPADDRESS;

        try {
            String ha = InetAddress.getLocalHost().getHostAddress();
            InetAddress[] a = InetAddress.getAllByName(ha);

            if (a.length == 1) {
                ip = a[0].getHostAddress();
            }
        } catch (UnknownHostException uhe) {}

        return ip;
    }
}
